﻿using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using ShopB2C.Entity;
using ShopB2C.Helper;
using ShopB2C.Interfaces;
using ShopB2C.ViewModels;

namespace ShopB2C.Controllers.Brower {
    public partial class BrandController : BaseController {
        private static IBrand _brand;
        private static IClassify _classify;
        private static string _path;
        private const string _moduleKey = "Brands";

        protected override void Initialize(RequestContext requestContext) {
            base.Initialize(requestContext);
            this.SiteMapPathAdd("首页", Url.Action("Index", "Home"));
            _path = this.Server.MapPath("~/BrandPictures/");
        }

        public BrandController() {
            _brand = DataBaseExecuter.CreateClassByName<IBrand>("Brand");
            _classify = DataBaseExecuter.CreateClassByName<IClassify>("Classify");
        }

        public ActionResult Index() {
            this.SiteMapPathAdd("品牌列表");

            return View(new BrandViewModel() {
                BrandList = _brand.GetBrandList(0, true),
                ClassifyList = _classify.GetClassifyByModuleKey(_moduleKey)
            });
        }

        public ActionResult View() {
            return View(new BrandViewModel());
        }

        [HttpPost]
        public ActionResult BrandList(int id) {
            List<BrandEntity> brandList = _brand.GetBrandList(id, null);
            // 显示文字链接
            ViewData["ShowRecommText"] = true;

            return View(brandList == null ? new List<BrandEntity>() : brandList);
        }
    }
}
